import { Component } from '@angular/core';

import { Platform, Events, AlertController, App, List, ModalController, NavParams, NavController, LoadingController } from 'ionic-angular';

import { InfoDetailService } from './detail.service';

import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';

import { Config } from '../../../../../providers/config';

import { Common } from "../../../../../providers/common";

import { Storage } from '@ionic/storage';

// pdf容器
import { PdfViewerComponent } from 'ng2-pdf-viewer';

import _ from 'lodash';

@Component({
  selector: 'page-irp-report-outside-detail',
  templateUrl: './detail.html',
  providers: [InfoDetailService]
})
export class
IrpReportOutsideDetailPage {

  info;

  username =sessionStorage.getItem("key");

  //登录人orgid
  public orgid;

  //评论信息
  commontInfo;

  //报告附件
  reportFile;

  //评论输入框显示
  public isCommentStatus= false;

  //评论输入框信息
  entryInfo='';


  constructor(
    public alertCtrl: AlertController,
    public app: App,
    public sanitizer: DomSanitizer,
    public platform: Platform,
    public storage: Storage,
    public navParams: NavParams,
    public loadingCtrl: LoadingController,
    public modalCtrl: ModalController,
    public navCtrl: NavController,
    public listService: InfoDetailService,
    private common: Common,
  ) {
    this.info = this.navParams.data;
    console.log(this.info)
    this.getCommontInfo();
    this.getreportFile();
    this.getOrgid()


  }

  //获取登录人的orgid
  getOrgid(username=this.username){
    this.listService.getOrgid(username).subscribe(
      data =>{
        this.orgid=data[0].orgid
      }
    )
  }

  //获取报告评论
  getCommontInfo(){
    this.listService.getCommontInfo().subscribe(
      data =>{
        // console.log(data)
        this.commontInfo = data;
      }
    )
  }

  //下载附件
  openFile(id,name)
{
  this.common.openFile('email', 'normal', id, name, false);
  console.log(id)
}
  //获取外部报告附件
  getreportFile(){
    this.listService.getreportFile().subscribe(
      data =>{
        console.log(data)
        this.reportFile = data;
      }
    )
  }

  //插入评论
  insertCommont(entry=this.entryInfo,objid=this.info.objid,orgid=this.orgid){
    this.listService.insertCommont(entry,objid,orgid).subscribe(
      data =>{
          this.getCommontInfo()
          this.entryInfo=''
      }
    )
  }

 //评论输入框显示
  toggleComment(status){
    if(status=='start'){
      this.isCommentStatus = true;
    }
    if(status=='end'){
      this.isCommentStatus = false;
    }
  }

}
